package dao.impl;

import dao.DeptDao;
import org.apache.ibatis.session.SqlSession;
import pojo.Dept;
import util.MyBatisUtil;

import java.util.List;

public class DeptDaoImpl implements DeptDao {


    @Override
    public List<Dept> findAll(Dept dept) {
      return MyBatisUtil.getSession().getMapper(DeptDao.class).findAll(dept);
    }

    @Override
    public int add(Dept dept) {
        SqlSession session = MyBatisUtil.getSession();
        int result = session.getMapper(DeptDao.class).add(dept);
        // ·提交事务
        session.commit();
        return result;
    }

    @Override
    public int delete(int id) {
        SqlSession session = MyBatisUtil.getSession();
        int result = session.getMapper(DeptDao.class).delete(id);
        // ·提交事务
        session.commit();
        return result;
    }

    @Override
    public Dept findById(int id) {
        return MyBatisUtil.getSession().getMapper(DeptDao.class).findById(id);
    }

    @Override
    public int update(Dept dept) {
        SqlSession session = MyBatisUtil.getSession();
        int result = session.getMapper(DeptDao.class).update(dept);
        // ·提交事务
        session.commit();
        return result;
    }
}
